﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace BYManageInfoSystem
{
    public partial class Frm_LogManager : DockContent
    {
        DGBY.BLL.DG_OperLogTab m_bllDGOperLogTab = new DGBY.BLL.DG_OperLogTab();
        private DGBY.BLL.T_ACL_User m_bllT_ACL_User = new DGBY.BLL.T_ACL_User();

        public Frm_LogManager()
        {
            InitializeComponent();
            InitUltraDropDown();
        }

        private void InitColumnWidth()
        {
            ultraGrid1.DisplayLayout.Bands[0].Columns["序号"].Width = 40;
            ultraGrid1.DisplayLayout.Bands[0].Columns["操作者"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["操作时间"].Width = 130;
            ultraGrid1.DisplayLayout.Bands[0].Columns["操作名称"].Width = 120;
            ultraGrid1.DisplayLayout.Bands[0].Columns["模块名称"].Width = 100;
            ultraGrid1.DisplayLayout.Bands[0].Columns["单据名称及序号"].Width = 140;
        }

        private void InitUltraDropDown()
        {
            DataSet dsTemp = m_bllT_ACL_User.GetList("");

            this.ultraDropDownUserList.DataSource = dsTemp.Tables[0];
            this.ultraDropDownUserList.DisplayMember = "用户名称";
            this.ultraDropDownUserList.ValueMember = "UserPasswordTabID";
            this.ultraDropDownUserList.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownUserList.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownUserList.DisplayLayout.Bands[0].Columns[i].Hidden = true;

            this.ultraDropDownUserList.DisplayLayout.Bands[0].Columns["用户名称"].Hidden = false;
        }

        private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);
            InitColumnWidth();
        }

        private void buttonShowAll_Click(object sender, EventArgs e)
        {
            ShowAllRecord("");
        }

        private void ShowAllRecord(string strWhere)
        {
            DataSet ds = m_bllDGOperLogTab.GetList(strWhere);
            ultraGrid1.DataSource = null;

            ultraGrid1.DataSource = ds.Tables[0];
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["操作者"].ValueList = this.ultraDropDownUserList;
        }

        private void buttonExportExcel_Click(object sender, EventArgs e)
        {
            DataTable dt = (DataTable)ultraGrid1.DataSource;

            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Excel文件(*.xls)|*.xls";
                    string outFile = "";

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        outFile = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }

                    ultraGridExcelExporter1.Export(ultraGrid1, outFile);
                }
            }
        }
    }
}
